﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace System.Linq
{
	public static class WhereIfExtension
		{
			public static IQueryable<T> WhereIf<T>(this IQueryable<T> source, Expression<Func<T, bool>> predicate, bool condition)
			{
				return condition ? source.Where(predicate) : source;
			}
			public static IQueryable<T> WhereIf<T>(this IQueryable<T> source, Expression<Func<T, int, bool>> predicate, bool condition)
			{
				return condition ? source.Where(predicate) : source;
			}
			public static IEnumerable<T> WhereIf<T>(this IEnumerable<T> source, Func<T, bool> predicate, bool condition)
			{
				return condition ? source.Where(predicate) : source;
			}
			public static IEnumerable<T> WhereIf<T>(this IEnumerable<T> source, Func<T, int, bool> predicate, bool condition)
			{
				return condition ? source.Where(predicate) : source;
			}
		}
}

